//
//  AXHdzqJfFruitsVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/5.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXHdzqJfFruitsVC.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "Header.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "AXHdzqJfFruitsCell.h"
#import "AXHdzqJfFruitsModel.h"

@interface AXHdzqJfFruitsVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray<AXHdzqJfFruitsModel *>  *modelsArray;
/** 假图片数据 */
@property (nonatomic, strong) NSArray<NSString *> *imageNames;
@property (nonatomic, strong) NSArray<NSString *> *titleNames;
@property (nonatomic, strong) NSArray<NSString *> *storeNames;
@property (nonatomic , assign) NSInteger requstIndex;


@end

@implementation AXHdzqJfFruitsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    self.view.backgroundColor = [UIColor redColor];
    
}




- (void)creatView {
    /** 表头创建 */
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXHdzqJfFruitsCell class] forCellReuseIdentifier:[AXHdzqJfFruitsCell reuseID]];
    [self.view addSubview:self.tableView];
    
}


- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, 0)
    .widthIs(Wi)
    .heightIs(MyTableViewHeight);
    
    
}

- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    /** title */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"正在疯抢";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)search:(UIButton *)btn {
    
}



#pragma mark - tableViewDelegate & tableViewDatasorce



//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 10;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[AXHdzqJfFruitsCell class] contentViewWidth:SCREEN_WIDTH];
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    AXHdzqJfFruitsCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXHdzqJfFruitsCell reuseID] forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    NSArray<NSString *>  *images = @[@"sg1.jpeg",@"sg2.jpeg",@"sg3.jpeg",@"sg4.jpeg",@"sg5.jpeg",@"sg1.jpeg",@"sg2.jpeg",@"sg3.jpeg",@"sg4.jpeg",@"sg5.jpeg"];
    NSArray<NSString *>  *titles = @[@"苹果",@"香蕉",@"葡萄",@"橘子",@"荔枝",@"苹果",@"香蕉",@"葡萄",@"橘子",@"荔枝"];
    cell.productImageView.image = [UIImage imageNamed:images[indexPath.row]];
    cell.productNameLabel.text = titles[indexPath.row];
    
    
    
    
    return cell;
    
    
}





@end

